import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:razer_one/app/main/utils/alert_utils.dart';
import 'package:razer_one/app/main/utils/permission_utils.dart';

class ImageUtil {
  //保存图片
  static saveImageWithUrl(String url, context) async {
    bool isPermission = await PermissionUtil.checkPermissionPhotos(context);
    if (!isPermission) return;
    AlertUtils.showStatus("保存中...");
    var response = await Dio()
        .get(url, options: Options(responseType: ResponseType.bytes));
    final result = await ImageGallerySaver.saveImage(
        Uint8List.fromList(response.data),
        quality: 60,
        name: '${DateTime.now()}.png');
    AlertUtils.dismiss();
    if (result["isSuccess"]) {
      AlertUtils.show("保存成功");
    } else {
      AlertUtils.show("保存失败");
    }
  }
}
